<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="UTF-8">
  <title>注册账号-权限管理系统</title>
  <meta th:include="~{layout/head_xadmin :: content}">
</head>
<body class="login-bg">

<div class="login layui-anim layui-anim-up">
  <div class="message">权限管理系统-用户注册</div>
  <div id="darkbannerwrap"></div>
  <form method="post" class="layui-form">
    <input name="username" placeholder="账号" type="text" lay-verify="required" class="layui-input">
    <hr class="hr15">
    <input name="password" lay-verify="required" placeholder="密码" type="password" class="layui-input">
    <hr class="hr15">
    <input name="password2" lay-verify="required" placeholder="确认密码" type="password" class="layui-input">
    <hr class="hr15">
    <input name="nickname" lay-verify="required" placeholder="昵称" type="text" class="layui-input">
    <hr class="hr15">
    <br>
    <input value="立即注册" lay-submit lay-filter="register" style="width:100%;" type="submit">
    <hr class="hr20">
  </form>
  <a href="/login">返回登录</a>
</div>

<script>
  layui.use(['form', 'jquery', 'layer'], function () {
    var form = layui.form;
    var $ = layui.jquery;
    var layer = layui.layer;
    //监听提交
    form.on('submit(register)', function (data) {
      var datas = data.field
      if (datas.password != datas.password2) {
        layer.msg('两次输入的密码不一致', {icon: 5});
        return false;
      }
      $.ajax({
        data: datas,
        url: '/register',
        type: 'post',
        success(data) {
          if (data.code == 0) {
            layer.msg(data.message, {icon: 1})
          } else {
            layer.msg(data.message, {icon: 2});
          }
        }
      })
      return false;
    });
  });
</script>
</body>
</html>
